package com.gyg.controller;


import com.gyg.client.CloudSpaceClient;
import com.gyg.domain.CloudUser;
import com.gyg.enums.SessionEnum;
import com.gyg.returns.RespCode;
import com.gyg.returns.RespEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Objects;

/**
 * <p>
 * 云盘空间表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/cloud-space")
@Api(value = "云盘空间", tags = "云盘空间")
@Slf4j
public class CloudSpaceController {

    @Resource
    private CloudSpaceClient cloudSpaceClient;

    @GetMapping("/info")
    @ApiOperation(value = "云盘容量信息")
    public RespEntity cloudSpaceInfo(HttpSession session) {
        CloudUser cloudUser = (CloudUser) session.getAttribute(SessionEnum.USER.getCode());
        if (Objects.isNull(cloudUser)) {
            return new RespEntity(RespCode.USER_NOT_FOUND);
        }

        RespEntity respEntity = cloudSpaceClient.getCloudSpaceInfo(cloudUser.getId());
        return respEntity;
    }

}
